﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyControls
{
    public partial class THMeter : UserControl
    {
        public THMeter()
        {
            InitializeComponent();
        }

        //设置温湿度柱显示和实际温湿度显示【只读】
        private int barHight = 121;

        public double SetHTValue
        {
            set
            {
                if(value <0 || value > 70)
                {
                    MessageBox.Show("温度值必须在0-70之间!", "信息提示");
                }
                else
                {
                    double realValue = (barHight / 70.0) * value; //实际值对应的高度
                    //上面空白部分的遮罩高度
                    this.lblBar.Height = barHight - Convert.ToInt32(realValue);
                }
            }
        }

        //设置温湿度计的背景颜色【属性】
        private BgColor _bgColor;
        public BgColor SetBackColor
        {
            get
            {
                return _bgColor;
            }
            set
            {
                if(value == BgColor.Green)
                {
                    this.panelBg.BackgroundImage = Properties.Resources.green;
                }
                else
                {
                    this.panelBg.BackgroundImage = Properties.Resources.red;
                }
                _bgColor = value;
            }
        }

        /// <summary>
        /// 颜色枚举
        /// </summary>
        public enum BgColor
        {
            Red,
            Green
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
